package net.xxcxcxcx.xc_enhancedmob.packet;

import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketByteBuf;

import static net.xxcxcxcx.xc_enhancedmob.EnhancedMobMod.MoreNbtIdentifier;

public class CustomNbtPacket {
    public int id;
    public NbtCompound nbt;

    public CustomNbtPacket(PacketByteBuf buf) {
        id = buf.readInt();
        nbt = buf.readNbt();
    }

    public static PacketByteBuf write(int entityid, NbtCompound nbtCompound) {
        PacketByteBuf buf = PacketByteBufs.create();
        buf.writeInt(entityid);
        buf.writeNbt(nbtCompound);
        return buf;
    }

    public static Packet<?> creat(int entityid, NbtCompound nbtCompound) {
        return ServerPlayNetworking.createS2CPacket(MoreNbtIdentifier, write(entityid, nbtCompound));
    }
}
